package com.laijiale.controller;

import com.laijiale.dto.SeckillInsertDTO;
import com.laijiale.dto.SeckillPageDTO;
import com.laijiale.dto.SeckillUpdateDTO;
import com.laijiale.entity.Seckill;
import com.laijiale.service.SeckillService;
import com.laijiale.vo.SeckillSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.laijiale.entity.Seckill;
import com.laijiale.service.SeckillService;

import java.util.List;

/**
 * 秒杀表 控制层。
 *
 * @author laijiale
 * @since 2024-12-22
 */
@RestController
@RequestMapping("/seckill")
public class SeckillController {

    @Autowired
    private SeckillService noticeService;


    @Operation(summary ="新增－ 单条",description ="新增一条秒杀记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody SeckillInsertDTO dto) {
        return noticeService.insert(dto);
    }
    @Operation(summary="查询－ 单条",description="按主键查询一条秒杀记录")
    @GetMapping("select/{id}")
    public Seckill select(@PathVariable("id") Long id) {
        return noticeService.select(id);
    }
    @Operation(summary="查询－ 查询前N条",description="按主键查询前N秒杀记录")
    @GetMapping("top/{N}")
    public List<Seckill> top(@PathVariable("N") Long N) {
        return noticeService.top(N);
    }
    @Operation(summary ="查询－ 简单全查",description="查询全部秒杀记录")
    @GetMapping("simpleList")
    public List<SeckillSimpleListVO> simpleList() {
        return noticeService.simpleList();
    }
    @Operation(summary="查询－ 分页",description ="分页查询秒杀记录")
    @GetMapping("page")
    public Page<Seckill> page(@Validated SeckillPageDTO dto) {
        return noticeService.page(dto);
    }

    @Operation(summary="修改－单条",description ="按主键修改一条秒杀记录")
    @PutMapping("update")
    public boolean update(@RequestBody SeckillUpdateDTO dto) {
        return noticeService.update(dto);
    }
    @Operation(summary="删除－ 单条",description="按主键删除一条秒杀记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return noticeService.delete(id);
    }
    @Operation(summary="删除－ 批量",description ="按主键批量删除秒杀记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return noticeService.deleteBatch(ids);
    }

}
